<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="用户注册时间">
        <el-date-picker
          v-model="userQuery.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="userQuery.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row>
      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="userName" label="用户名" width="260" align="center"/>
      <el-table-column  label="性别" width="60">
        <template slot-scope="scope">
          {{ scope.row.sex===true?'男':'女' }}
        </template>
      </el-table-column>
      <el-table-column prop="gmtCreate" label="注册时间" width="260" align="center"/>
      <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
          <el-button  type="primary" size="mini" icon="el-icon-edit" @click="acceptUser(scope.row.userId)">通过
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>

<script>
import userApi from "../../api/qa/userManage";
export default {
name: "check",
  data() {
    return {
      list: null,
      page: 1,
      limit: 5,
      total: 0,
      userQuery: {},
      listLoading:true
    }
  },
  created() {
    this.getList()
    this.listLoading=false;
  },
  methods: {
    getList(page = 1) {
      this.page = page
      userApi.getUserListPage(this.page, this.limit, this.questionQuery)
        .then(response => {
          const data = response.data
          this.list = data.rows
          this.total = data.total
        }).catch(error => {
        console.log(error)
      })
    },
    resetData() {
      this.questionQuery = {}
      this.getList()
    },
    acceptUser(id) {
      this.$confirm('此操作将批准该用户的注册申请?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        userApi.acceptUserById(id)
          .then(response => {
            this.$message({
              type: 'success',
              message: '已批准!'
            })
            this.getList(this.page)
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })

    }
  }

}
</script>

<style scoped>

</style>
